//
//	(c) 2009 Andrew Kalmacky
//

#include "logger.h"
#include <Windows.h>
#include <stdio.h>

namespace Log
{
        void OutStr(const char_t *s)
    {
                //fputws(s, stderr);
                OutputDebugStr(s);
    }

    Stream &operator<< (Stream& s, const int v)
    {
        char_t buf[14];
                char_t *pos = buf + sizeof(buf) / sizeof(char_t) - 1;
        *pos = 0;
        int dv = abs(v);
        do
        {
            *--pos = dv % 10 + T_('0');
            dv /= 10;
        }
        while(dv);

        if (v < 0)
            *--pos = '-';
        return s << pos;
    }

    Stream &operator<< (Stream& s, const void* const v)
    {
        char_t buf[14];
                char_t *pos = buf + sizeof(buf) / sizeof(char_t) - 1;
        *pos = 0;
        size_t dv = reinterpret_cast<size_t> (v);
        do
        {
            size_t t = dv & 0xf;
            *--pos = char_t(t < 10 ? (t + T_('0')) : (t - 10 + T_('a')));
            dv >>= 4;
        }
        while(dv);
        return s << pos;
    }
        template<> const char_t *const LevelInfo<lv_Verbose>::name = T_("[v]");
        template<> const char_t *const LevelInfo<lv_Info>::name    = T_("[i]");
        template<> const char_t *const LevelInfo<lv_Warning>::name = T_("[w]");
        template<> const char_t *const LevelInfo<lv_Fatal>::name   = T_("[f]");

        template<> const char_t* const memory::prefix = T_("[memory]");
        template<> const char_t* const ltm::prefix = T_("[ltm]");
        template<> const char_t* const app::prefix = T_("[app]");
        template<> const char_t* const test::prefix = T_("[test]");
}
